<?php

namespace app\controllers;

use yii\web\Controller;
use Yii;
use app\models\report;

class ReportController extends Controller{
      public $enableCsrfValidation = false;
      public function actionCheckin(){
         $model = new report();
         if(Yii::$app->request->isPost){
             $postData = Yii::$app->request->post();
             $openid = $postData['openId'];
             $nickname = $postData['nickname'];
             $data = $model->getByOpenId($postData['openId']);
               if($data && $data['openid'] == $postData['openId']){
                 $sql = "select rankId,openid,time,college,major,nickname,avatarUrl from freshmanHelper_report where openid = '$openid'";
                 $data = report ::findBysql($sql)->asArray()->one();
                 echo json_encode(array('error' => 0,'data' => $data,));
        }else{
               $result = $model->add($postData);
               $sql = "select rankId,openid,time,college,major,nickname,avatarUrl from freshmanHelper_report where openid = '$openid' and nickname = '$nickname'";
               $data = report ::findBysql($sql)->asArray()->one();
               echo json_encode(array('error' => 0,'data' => $data,));
        } 
     }
  }
}
